home *** CD-ROM | disk | FTP | other *** search
- /* PointHack.c
-
- * Changes mouse colour on single and double mouse press
- * runs as a commodity
- * requires V38 of commodities.library
- *
- * Freely distributable
- *
- * mpaddock@cix.compulink.co.uk
- */
-
- #include <intuition/intuitionbase.h>
- #include <clib/intuition_protos.h>
- struct IntuitionBase *IntuitionBase;
- #include <pragmas/intuition_pragmas.h>
-
- #include <clib/exec_protos.h>
- extern struct Library *SysBase;
- #include <pragmas/exec_pragmas.h>
-
- #include <clib/graphics_protos.h>
- struct Library *GfxBase;
- #include <pragmas/graphics_pragmas.h>
-
- #include <clib/commodities_protos.h>
- struct Library *CxBase;
- #include <pragmas/commodities_pragmas.h>
-
- #include <clib/icon_protos.h>
- struct Library *IconBase;
- #include <pragmas/icon_pragmas.h>
-
- #include <devices/timer.h>
-
- #include <clib/timer_protos.h>
- struct Library *TimerBase=NULL;
- #include <pragmas/timer_pragmas.h>
-
- #include <clib/alib_protos.h>
-
- #include <dos/dos.h>
-
- void
- ColorPointer(BOOL doubleclick);
-
- void
- UnColorPointer(void);
-
- UBYTE *vers = "$VER: PointHack 1.0 (16.5.93)";
-
- UBYTE dr[3],dg[3],db[3];
- UBYTE ddr[3],ddg[3],ddb[3];
-
- void
- main(int argc, char **argv) {
- struct NewBroker newbroker = {
- NB_VERSION,
- "PointHack 1.0",
- "Pointer colour changer",
- "Change pointer colour on mouse press",
- NBU_UNIQUE|NBU_NOTIFY,
- 0,
- 0,
- 0,
- 0
- };
- struct timeval time1, time2;
- struct timerequest tr;
- UBYTE **ttypes;
- struct MsgPort *broker_mp;
- CxMsg *msg;
- CxObj *broker,*down,*up,*upf,*downf;
- ULONG downs,ups;
- ULONG signals = SIGBREAKF_CTRL_C;
- ULONG sigrcvd;
- struct Task *task;
- BOOL flag = TRUE;
- if (IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37)) {
- if (GfxBase = OpenLibrary("graphics.library",37)) {
- if (IconBase = OpenLibrary("icon.library",37)) {
- if (CxBase = OpenLibrary("commodities.library",38)) {
- if (broker_mp = CreateMsgPort()) {
- signals |= (1L << broker_mp->mp_SigBit);
- ttypes = ArgArrayInit(argc,argv);
- dr[0] = (UBYTE)ArgInt(ttypes,"R1",0);
- dr[1] = (UBYTE)ArgInt(ttypes,"R2",0);
- dr[2] = (UBYTE)ArgInt(ttypes,"R3",0);
- dg[0] = (UBYTE)ArgInt(ttypes,"G1",0);
- dg[1] = (UBYTE)ArgInt(ttypes,"G2",0);
- dg[2] = (UBYTE)ArgInt(ttypes,"G3",0);
- db[0] = (UBYTE)ArgInt(ttypes,"B1",0);
- db[1] = (UBYTE)ArgInt(ttypes,"B2",0);
- db[2] = (UBYTE)ArgInt(ttypes,"B3",0);
- ddr[0] = (UBYTE)ArgInt(ttypes,"DR1",15);
- ddr[1] = (UBYTE)ArgInt(ttypes,"DR2",15);
- ddr[2] = (UBYTE)ArgInt(ttypes,"DR3",15);
- ddg[0] = (UBYTE)ArgInt(ttypes,"DG1",15);
- ddg[1] = (UBYTE)ArgInt(ttypes,"DG2",15);
- ddg[2] = (UBYTE)ArgInt(ttypes,"DG3",15);
- ddb[0] = (UBYTE)ArgInt(ttypes,"DB1",15);
- ddb[1] = (UBYTE)ArgInt(ttypes,"DB2",15);
- ddb[2] = (UBYTE)ArgInt(ttypes,"DB3",15);
- newbroker.nb_Port = broker_mp;
- newbroker.nb_Pri = (BYTE)ArgInt(ttypes,"CX_PRIORITY",0);
- task = FindTask(NULL);
- if (broker = CxBroker(&newbroker,NULL)) {
- if (upf = CxFilter("rawmouse -caps -alt -lcommand -rcommand -control leftbutton upstroke mouse_leftpress")) {
- AttachCxObj(broker, upf);
- if (downf = CxFilter("rawmouse -caps -alt -lcommand -rcommand -control leftbutton mouse_leftpress")) {
- AttachCxObj(broker, downf);
- if ((downs = (ULONG)AllocSignal(-1L)) != -1) {
- signals |= (1L << downs);
- if (down = CxSignal(task,downs)) {
- AttachCxObj(downf,down);
- if ((ups = (ULONG)AllocSignal(-1L)) != -1) {
- signals |= (1L << ups);
- if (up = CxSignal(task,ups)) {
- AttachCxObj(upf,up);
- if (!OpenDevice(TIMERNAME,UNIT_MICROHZ,(struct IORequest *) &tr, 0L)) {
- TimerBase = (struct Library *)tr.tr_node.io_Device;
- ActivateCxObj(broker,TRUE);
- while (flag) {
- sigrcvd = Wait(signals);
- if (sigrcvd & (1L << broker_mp->mp_SigBit)) {
- while (msg = (CxMsg *)GetMsg(broker_mp)) {
- switch (CxMsgType(msg)) {
- case CXM_COMMAND:
- switch (CxMsgID(msg)) {
- case CXCMD_DISABLE:
- ActivateCxObj(broker,FALSE);
- UnColorPointer();
- break;
- case CXCMD_ENABLE:
- ActivateCxObj(broker,TRUE);
- break;
- case CXCMD_KILL:
- case CXCMD_UNIQUE:
- flag = FALSE;
- break;
- default:
- break;
- }
- default:
- break;
- }
- ReplyMsg((struct Message *)msg);
- }
- }
- if (sigrcvd & SIGBREAKF_CTRL_C) {
- flag = FALSE;
- }
- if (sigrcvd & (1L << downs)) {
- if (!(sigrcvd & (1L << ups))) {
- GetSysTime(&time2);
- ColorPointer(DoubleClick(time1.tv_secs,time1.tv_micro,
- time2.tv_secs,time2.tv_micro));
- time1 = time2;
- }
- }
- if (sigrcvd & (1L << ups)) {
- UnColorPointer();
- }
- }
- UnColorPointer();
- CloseDevice((struct IORequest *) &tr);
- }
- }
- FreeSignal(ups);
- }
- }
- FreeSignal(downs);
- }
- }
- }
- while (msg = (CxMsg *)GetMsg(broker_mp)) {
- ReplyMsg((struct Message *)msg);
- }
- DeleteCxObjAll(broker);
- }
- DeletePort(broker_mp);
- }
- CloseLibrary(CxBase);
- }
- CloseLibrary(IconBase);
- }
- CloseLibrary(GfxBase);
- }
- CloseLibrary((struct Library *)IntuitionBase);
- }
- }
-
- UBYTE r[3],g[3],b[3]; /* Saved rgb colors */
- struct Screen *screen=NULL;
-
- /* Colour the pointer
- */
- void
- ColorPointer(BOOL doubleclick) {
- UWORD i; /* Loop counter */
- UWORD color; /* Colour */
- /* Store 3 colours */
- Forbid();
- screen = IntuitionBase->ActiveScreen;
- for (i=0; i<3; i++) {
- color = GetRGB4(screen->ViewPort.ColorMap,i+17);
- r[i]=(color&0x0f00)>>8;
- g[i]=(color&0x00f0)>>4;
- b[i]=(color&0x000f);
- }
- /* Update 3 colours */
- if (doubleclick) {
- for (i=0; i<3; i++) {
- SetRGB4(&(screen->ViewPort),17+i,ddr[i],ddg[i],ddb[i]);
- }
- }
- else {
- for (i=0; i<3; i++) {
- SetRGB4(&(screen->ViewPort),17+i,dr[i],dg[i],db[i]);
- }
- }
- Permit();
- }
-
- /* UnColour the pointer
- */
- void
- UnColorPointer(void) {
- UWORD i; /* Loop counter */
- /* redo 3 colours */
- Forbid();
- if (screen) {
- for (i=0; i<4; i++) {
- SetRGB4(&(screen->ViewPort),17+i,r[i],g[i],b[i]);
- }
- }
- screen = NULL;
- Permit();
- }
-